package com.shdanyan.dao;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.test.context.junit4.SpringRunner;

import com.shdanyan.domain.sys.SysUserInfo;
import com.shdanyan.mapper.SysUserInfoMapper;

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class UserMapperTest2 {
    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private SysUserInfoMapper userMapper;

    /**
     * 根据主键全更新
     */
    @Test
    public void testUpdateByPrimaryKey() {
        SysUserInfo userInfo = userMapper.selectByPrimaryKey((long) 1);
        Assert.assertNotNull(userInfo);
        userInfo.setUsertype(null);
        userInfo.setEmail("abel534@gmail.com");
        // 不会更新username
        Assert.assertEquals(1, userMapper.updateByPrimaryKey(userInfo));

        userInfo = userMapper.selectByPrimaryKey(userInfo);
        Assert.assertNull(userInfo.getUsertype());
        Assert.assertEquals("abel533@gmail.com", userInfo.getEmail());
    }

    @Test
    public void test() throws Exception {

        SysUserInfo userInfo2 = userMapper.selectByPrimaryKey((long) 4);
        System.out.println(userInfo2.getUsername());
    }

}
